package cn.beyondPlatform.wei.controller;


import cn.beyondPlatform.wei.exception.LoginException;

import cn.beyondPlatform.wei.pojo.DevUser;
import cn.beyondPlatform.wei.service.BackendUser.BackendUserService;
import cn.beyondPlatform.wei.service.devuser.DevUserService;
import cn.beyondPlatform.wei.utils.AjaxResult;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;


@RestController
@RequestMapping("/toDevUser")
public class DevUserController {

    @Autowired
    private BackendUserService backendUserService;

    @Autowired
    private DevUserService userService;

    @GetMapping("/getLoginUser")
    public AjaxResult getLoginUser(HttpSession session) {
        DevUserController user = (DevUserController) session.getAttribute("loginUser");
        if (user == null) {
            return AjaxResult.error();
        }

        return AjaxResult.success(user);
    }

    /**
     * 后台管理登录
     *
     * @param userCode-
     * @param userPassword
     * @return
     */
    @PostMapping("/devUser")
    public AjaxResult devLogin(@RequestParam(required = false) String userCode, @RequestParam(required = false) String userPassword) throws LoginException {
        System.out.print("11");
        DevUser devUser = userService.devLogin(userCode, userPassword);
        System.out.print("222");
        if (devUser == null) {
            return AjaxResult.error("用户或密码不正确");
        }
        return AjaxResult.success(devUser);
    }

}
